#!/bin/bash
# Check if dummy-source connected
rel_id=$(relation-ids source)
if [[ -z $rel_id ]]; then
	status-set blocked "Waiting for source relation"
else
	mkdir -p /var/run/dummy-sink
	token=$(relation-get token -r "$rel_id" dummy-source/0)
	echo "$token" >/var/run/dummy-sink/token
	if [ -z "$token" ]; then
		juju-log -l INFO "Waiting for token"
		status-set blocked "Waiting for token" || true
	else
		juju-log -l INFO "Token is $token"
		status-set active "Token is $(echo "$token" | cut -c 1-20)" || true
	fi
fi
